#include <functional>
#include <cstdio>

#include "thread/ThreadPool.h"
#include "thread/Latch.h"
#include "thread/current_thread.h"


void print()
{
  printf("tid=%d\n", CurrentThread::tid());
}

void printString(const std::string& str)
{
  printf("tid=%d, str=%s\n", CurrentThread::tid(), str.c_str());
}

int main()
{
  ThreadPool pool(100, "MainThreadPool");
  pool.start(5);

  pool.run(print);
  pool.run(print);
  for (int i = 0; i < 100; ++i)
  {
    char buf[32];
    snprintf(buf, sizeof(buf), "task %d", i);
    pool.run(std::bind(printString, std::string(buf)));
  }

  Latch latch(1);
  pool.run([&latch](){latch.count_down(); });
  latch.wait();
  pool.stop();
}

